using System.Linq;
using NUnit.Framework;

namespace Flit.Tests
{
    [TestFixture]
    public class TransitionTest : ParserTestBase
    {
        [Test]
        public void HasFrom()
        {
            Graph node = Parse("digraph g{x y; z z->x z-> y}");
            Assert.AreEqual("z", node.Transitions.First().FromIdentifier);
            Assert.AreEqual("z", node.Transitions.Last().FromIdentifier);
        }
        [Test]
        public void HasTo()
        {
            Graph node = Parse("digraph g{x y; z z->x z-> y}");
            Assert.AreEqual("x", node.Transitions.First().ToIdentifier);
            Assert.AreEqual("y", node.Transitions.Last().ToIdentifier);
        }
        [Test]
        public void HasLabel()
        {
            Graph node = Parse("digraph g{x y; z z->x[label=\"zzzz\"] z-> y}");
            Assert.AreEqual("zzzz", node.Transitions.First().Label.Name);
        }

        [Test]
        public void HasAttributes()
        {
            Graph node = Parse("digraph g{x y; z z->x[label=\"zzzz\", foo=bar, color=\"red\"] z-> y}");
            Transition transition = node.Transitions.First();
            Assert.AreEqual("zzzz", transition.Label.Name);
            Assert.AreEqual("bar", transition.GenericAttributes["foo"]);
            Assert.AreEqual("red", transition.GenericAttributes["color"]);
        }

        [Test]
        public void AsFormalMethodDefinition()
        {
            Graph node = Parse("digraph g{z->x[label=\"foo(int bar)\"]}");
            Transition transition = node.Transitions.Single();
            Assert.AreEqual("foo(int bar)", transition.AsFormalMethodDefinition);
        }

        [Test]
        public void AsFormalMethodDefinitionWithStateParameters()
        {
            Graph node = Parse("digraph g{x[label=\"X(string s)\"] z->x[label=\"foo(int bar)\"]}");
            Transition transition = node.Transitions.Single();
            Assert.AreEqual("foo(string s, int bar)", transition.AsFormalMethodDefinition);
        }

        [Test]
        public void AsMethodCall()
        {
            Graph node = Parse("digraph g{z->x[label=\"foo(int bar)\"]}");
            Transition transition = node.Transitions.Single();
            Assert.AreEqual("foo(bar)", transition.AsMethodCall);
        }

        [Test]
        public void AsMethodCallWithStateParameters()
        {
            Graph node = Parse("digraph g{x[label=\"X(string s)\"] z->x[label=\"foo(int bar)\"]}");
            Transition transition = node.Transitions.Single();
            Assert.AreEqual("foo(s, bar)", transition.AsMethodCall);
        }

    }
}